package com.javaGather.day4;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Test1 {
    public static void main(String[] args) {
        /**
         * 三种方式遍历集合
         */

        List<Student> students = new ArrayList<>();
        students.add(new Student("Jack", 21));
        students.add(new Student("Jack", 21));
        students.add(new Student("Jack", 21));


        //普通for循环
        System.out.println("--------普通for循环--------------");
        for (int i = 0; i < students.size(); i++) {
            System.out.println(students.get(i));
        }

        //增强for循环
        System.out.println("---------增强for循环-------------");
        for (Student student : students) {
            System.out.println(student);
        }


        //迭代器
        System.out.println("---------迭代器-------------");
        Iterator<Student> iterator = students.iterator();
        while (iterator.hasNext()) {
            Student student = iterator.next();
            System.out.println(student);
        }


    }
}
